const express = require("express");

const app = express();

const path = require("path");

const mysqlquery = require("./js/mysql.js");
app.listen(3000,()=>{
    console.log("3000端口已经打开");
})
app.set("view engine","ejs");
app.set("views",path.join(__dirname,"views"));
app.engine("html",require("ejs").__express);
app.use(express.urlencoded({extended:false}));
app.use(express.json());
app.use("/js",express.static(path.join(__dirname,"js")))
app.get("/",(req,res)=>{
    res.render("register.html");
})
app.post("/register",async (req,res)=>{
    let {username} = req.body;
     let sql = `select * from users where  username = ${username}`;
    let [flag] = await mysqlquery(sql);
    if(flag.username = username)
    {
        res.send({status:500,msg:"该用户已经存在"});
    }

})